/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package oids.frontEnd.util;

import oids.frontEnd.components.Component;

/**
 *
 * @author CJ
 */
public class GridWrapper {

    protected int length;
    protected int width;

    public GridWrapper(int width, int length){
        this.length = length;
        this.width = width;
    }

    public boolean outOfBounds(Component a){
        return a.getX() < 0 ||
                a.getX() > this.width ||
                a.getY() < 0 ||
                a.getY() > this.length;
    }

    public void replacePosition(Component a){
        if(sideToSide(a))
            decideForSide(a);
        else
            decideForUp(a);
    }
    
    protected boolean sideToSide(Component a){
        return a.getX() < 0 || a.getX() > this.width;
    }

    protected void decideForSide(Component a){
        if(a.getX() < 0)
            a.setX(this.width);
        else
            a.setX(0);
//        a.setY(this.length - a.getY());
    }

    protected void decideForUp(Component a){
        if(a.getY() < 0)
            a.setY(this.length);
        else
            a.setY(0);
//        a.setX(this.width - a.getX());
    }

}
